package com.kun.oa.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kun.oa.entity.Permission;
import com.kun.oa.mapper.PermissionExample;
import com.kun.oa.mapper.PermissionMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Classname PermissionServiceImpl
 * @Created by FangKun
 * @Date 2023/1/8 0008 下午 22:36
 */
@Component
@Service(version = "1.0.0", timeout = 10000, interfaceClass = IPermissionService.class)
public class PermissionServiceImpl implements IPermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public PageInfo<Permission> findByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        PermissionExample permissionExample = new PermissionExample();
        List<Permission> list = permissionMapper.selectByExample(permissionExample);
        return new PageInfo<>(list);
    }

    @Override
    public Permission findById(int id) {

        return permissionMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Permission permission) {
        // TODO Auto-generated method stub
        permissionMapper.updateByPrimaryKeySelective(permission);

    }

    @Override
    public void add(Permission permission) {
        // TODO Auto-generated method stub
        permissionMapper.insert(permission);
    }

    @Override
    public List<Permission> findAll() {
        PermissionExample example = new PermissionExample();
        return permissionMapper.selectByExample(example);
    }

    @Override
    public boolean deletePermissionById(int id) {
        return permissionMapper.deleteByPrimaryKey(id)>0 ? true : false;
    }
}
